package com.googlecode.imanager.jasper;

import net.sf.jasperreports.engine.JRDefaultStyleProvider;

import com.googlecode.imanager.client.Label;
import com.googlecode.imanager.client.bridge.ILabel;
import com.googlecode.imanager.client.report.Field;
import com.googlecode.imanager.core.base.BridgeApplication;
import com.googlecode.imanager.jasper.print.RText;

/**
 * @author wellsantos@wellsantos.com
 * @since 0.01
 */
public class RLabel extends RControl implements ILabel {

    public RLabel(BridgeApplication bridge, Label source) {
        super(bridge, source);
        getTarget().setVerticalAlignment(RText.VERTICAL_ALIGN_MIDDLE);
        getTarget().setHorizontalAlignment(RText.HORIZONTAL_ALIGN_LEFT);
    }

    @Override
    public void setDefaultStyleProvider(JRDefaultStyleProvider defaultStyleProvider) {
        getTarget().setDefaultStyleProvider(defaultStyleProvider);
    }

    @Override
    protected RText createTarget() {
        return new RText(this);
    }

    @Override
    public RText getTarget() {
        return (RText) target;
    }

    @Override
    public Label getSource() {
        return (Label) source;
    }

    @Override
    public void setText(String text) {
        getTarget().setText(text);
        if (source instanceof Field<?>){
            getTarget().setFieldValue(((Field<?>) source).getValue());
        } else {
            getTarget().setFieldValue(null);
        }
        // TODO getTarget().setValueClassName(getSource().getValueType());
    }

    @Override
    public void setOverflowHorz(boolean overflowHorz) {
        // TODO Auto-generated method stub
    }

    @Override
    public void setOverflowVert(boolean overflowVert) {
        // TODO Auto-generated method stub
    }

}
